/*
 * Flashlib - QB9 common Flash library
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.qb9.flashlib.utils
{
	import flash.display.FrameLabel;
	import flash.display.MovieClip;
	
	public final class MovieUtil
	{
		// Returns an array of label names
		public static function getLabels(mc:MovieClip):Array
		{
			var labels:Array = [];
			for each (var label:FrameLabel in mc.currentLabels)
				labels.push(label.name);
			return labels;
		}
		
		public static function hasLabel(mc:MovieClip, label:String):Boolean
		{
			return ArrayUtil.contains(getLabels(mc), label);
		}
		
		/** 
		 * Converts a json object into an array of labels.
		 * The keys must be the labels and the values the frame numbers.
		 */
		public static function makeLabels(data:Object):Array
		{
			var labels:Array = [];
			for (var label:String in data)
				labels.push(new FrameLabel(label, data[label]));
			return labels;
		}
		
	}
}